package com.example.settings;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebMvcSettings  implements WebMvcConfigurer {


    /**
     * 设置全局跨域
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        System.out.println("===========addCorsMappings===========");
        registry.addMapping("/**")  //支持跨域的url地址。**表示所有地址
                .allowedOriginPatterns("*")      //允许跨域的来源地址
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") //允许跨域的请求方式
                .allowCredentials(true)  //是否支持cookie
                .maxAge(3600)            //预检请求的有效时间， 3600秒
                .allowedHeaders("*");    //允许的请求头header

    }
}
